home *** CD-ROM | disk | FTP | other *** search
- function GameGrid(aRange)
- {
- this.init(aRange);
- }
- GameGrid.prototype.init = function(aRange)
- {
- this.pData = new Array(64);
- };
- GameGrid.prototype.setRange = function(aRange)
- {
- this.pColours = [1,2,3,4,5,6,7,8].slice(0,aRange);
- this.fillGrid();
- };
- GameGrid.prototype.checkGrid = function()
- {
- var _loc4_ = undefined;
- var _loc3_ = undefined;
- var _loc11_ = undefined;
- var _loc12_ = undefined;
- var _loc5_ = undefined;
- var _loc9_ = undefined;
- var _loc10_ = undefined;
- var _loc6_ = new Array();
- _loc4_ = _loc3_ = _loc11_ = _loc12_ = 0;
- _loc5_ = 0;
- while(_loc5_ < 64)
- {
- _loc9_ = _loc5_ >= 63 ? _loc5_ : _loc5_ * 8 % 63;
- _loc10_ = this.getCellColour(_loc9_);
- if(_loc10_ == _loc12_)
- {
- _loc3_ = _loc3_ + 1;
- }
- else
- {
- _loc12_ = _loc10_;
- if(_loc3_ > 2)
- {
- var _loc7_ = 1;
- while(_loc7_ <= _loc3_)
- {
- _loc6_.push(_loc9_ - _loc7_ * 8);
- _loc7_ = _loc7_ + 1;
- }
- _parent.scores_mc.updateBonus();
- _parent.scores_mc.updateScore(_loc3_);
- _parent.pirate_mc.parrot_mc.playCombo();
- _parent.timer_mc.addTimer(_loc3_);
- updateBlockCount();
- }
- _loc3_ = 1;
- }
- if(_loc9_ > 55)
- {
- if(_loc3_ > 2)
- {
- _loc7_ = 0;
- while(_loc7_ < _loc3_)
- {
- _loc6_.push(_loc9_ - _loc7_ * 8);
- _loc7_ = _loc7_ + 1;
- }
- _parent.scores_mc.updateBonus();
- _parent.scores_mc.updateScore(_loc3_);
- _parent.pirate_mc.parrot_mc.playCombo();
- _parent.timer_mc.addTimer(_loc3_);
- updateBlockCount();
- }
- _loc3_ = 0;
- }
- _loc10_ = this.getCellColour(_loc5_);
- if(_loc10_ == _loc11_)
- {
- _loc4_ = _loc4_ + 1;
- }
- else
- {
- _loc11_ = _loc10_;
- if(_loc4_ > 2)
- {
- _loc7_ = 1;
- while(_loc7_ <= _loc4_)
- {
- _loc6_.push(_loc5_ - _loc7_);
- _loc7_ = _loc7_ + 1;
- }
- _parent.scores_mc.updateBonus();
- _parent.scores_mc.updateScore(_loc4_);
- _parent.pirate_mc.parrot_mc.playCombo();
- _parent.timer_mc.addTimer(_loc4_);
- updateBlockCount();
- }
- _loc4_ = 1;
- }
- if((_loc5_ + 1) % 8 == 0)
- {
- if(_loc4_ > 2)
- {
- _loc7_ = 0;
- while(_loc7_ < _loc4_)
- {
- _loc6_.push(_loc5_ - _loc7_);
- _loc7_ = _loc7_ + 1;
- }
- _parent.scores_mc.updateBonus();
- _parent.scores_mc.updateScore(_loc4_);
- _parent.pirate_mc.parrot_mc.playCombo();
- _parent.timer_mc.addTimer(_loc4_);
- updateBlockCount();
- }
- _loc4_ = 0;
- }
- _loc5_ = _loc5_ + 1;
- }
- if(_loc6_.length > 1)
- {
- var _loc13_ = _loc6_.length;
- var _loc8_ = 0;
- while(_loc8_ < _loc13_)
- {
- if(this.getCellColour(_loc6_[_loc8_]) == 0)
- {
- _loc6_.splice(_loc8_,1);
- _loc13_ = _loc13_ - 1;
- _loc8_ = _loc8_ - 1;
- }
- else
- {
- this.pData[_loc6_[_loc8_]] = 0;
- }
- _loc8_ = _loc8_ + 1;
- }
- }
- return _loc6_;
- };
- GameGrid.prototype.removeBlocks = function()
- {
- var _loc9_ = new Array([],[]);
- var _loc10_ = this.pData.slice();
- var _loc3_ = this.pColours.slice();
- var _loc5_ = undefined;
- var _loc2_ = undefined;
- var _loc8_ = undefined;
- var _loc7_ = 56;
- while(_loc7_ < 64)
- {
- _loc5_ = 0;
- _loc2_ = _loc7_ + 0;
- _loc8_ = 0;
- while(_loc2_ >= 0)
- {
- if(_loc10_[_loc2_] == 0)
- {
- if(_loc3_.length == 0)
- {
- _loc3_ = this.pColours.slice();
- }
- else
- {
- var _loc4_ = _loc3_[Math.round(Math.random() * (_loc3_.length - 1))];
- _loc3_.splice(_loc3_.getItemIndex(_loc4_),1);
- }
- var _loc6_ = _loc7_ - 56 + _loc8_ * 8;
- _loc9_[1].push(new Array(_loc2_,_loc6_,_loc4_));
- this.pData[_loc6_] = _loc4_;
- _loc8_ = _loc8_ + 1;
- _loc5_ = _loc5_ + 1;
- }
- else if(_loc5_ > 0)
- {
- _loc9_[0].push(new Array(_loc2_,_loc5_));
- this.pData[_loc2_ + _loc5_ * 8] = _loc10_[_loc2_];
- }
- _loc2_ -= 8;
- }
- _loc7_ = _loc7_ + 1;
- }
- return _loc9_;
- };
- GameGrid.prototype.checkBlocks = function(tCellNum)
- {
- var _loc12_ = undefined;
- var _loc11_ = undefined;
- var _loc6_ = undefined;
- var _loc14_ = undefined;
- var _loc16_ = undefined;
- var _loc15_ = undefined;
- var _loc17_ = undefined;
- var _loc3_ = undefined;
- var _loc7_ = undefined;
- var _loc8_ = undefined;
- var _loc10_ = undefined;
- var _loc9_ = undefined;
- _loc12_ = new Array();
- _loc11_ = new Array();
- _loc6_ = this.getCellColour(tCellNum);
- _loc14_ = Math.floor(tCellNum / 8);
- _loc16_ = 7 - _loc14_;
- _loc15_ = tCellNum - Math.floor(tCellNum / 8) * 8;
- _loc17_ = 7 - _loc15_;
- _loc7_ = 1;
- while(_loc7_ <= _loc14_)
- {
- _loc3_ = tCellNum - _loc7_ * 8;
- if(this.getCellColour(_loc3_) != _loc6_)
- {
- break;
- }
- _loc11_.push(_loc3_);
- _loc7_ = _loc7_ + 1;
- }
- _loc8_ = 1;
- while(_loc8_ <= _loc16_)
- {
- _loc3_ = tCellNum + _loc8_ * 8;
- if(this.getCellColour(_loc3_) != _loc6_)
- {
- break;
- }
- _loc11_.push(_loc3_);
- _loc8_ = _loc8_ + 1;
- }
- _loc10_ = 1;
- while(_loc10_ <= _loc15_)
- {
- _loc3_ = tCellNum - _loc10_;
- if(this.getCellColour(_loc3_) != _loc6_)
- {
- break;
- }
- _loc12_.push(_loc3_);
- _loc10_ = _loc10_ + 1;
- }
- _loc9_ = 1;
- while(_loc9_ <= _loc17_)
- {
- _loc3_ = tCellNum + _loc9_;
- if(this.getCellColour(_loc3_) != _loc6_)
- {
- break;
- }
- _loc12_.push(_loc3_);
- _loc9_ = _loc9_ + 1;
- }
- var _loc13_ = new Array();
- _loc13_.push(tCellNum);
- if(_loc12_.length >= 2)
- {
- _loc13_ = _loc13_.concat(_loc12_);
- _parent.scores_mc.updateBonus();
- _parent.scores_mc.updateScore(_loc12_.length + 1);
- _parent.timer_mc.addTimer(_loc12_.length + 1);
- updateBlockCount();
- }
- if(_loc11_.length >= 2)
- {
- _loc13_ = _loc13_.concat(_loc11_);
- _parent.scores_mc.updateBonus();
- _parent.scores_mc.updateScore(_loc11_.length + 1);
- _parent.timer_mc.addTimer(_loc11_.length + 1);
- updateBlockCount();
- }
- if(_loc13_.length > 1)
- {
- _parent.soul_mc.addTile(_loc6_);
- var _loc18_ = _loc13_.length;
- var _loc4_ = 0;
- while(_loc4_ < _loc18_)
- {
- this.pData[_loc13_[_loc4_]] = 0;
- _loc4_ = _loc4_ + 1;
- }
- }
- return _loc13_;
- };
- GameGrid.prototype.swapBlocks = function(tCellID1, tCellID2)
- {
- var _loc3_ = this.getCellColour(tCellID1);
- var _loc2_ = this.getCellColour(tCellID2);
- this.pData[tCellID1] = _loc2_;
- this.pData[tCellID2] = _loc3_;
- };
- GameGrid.prototype.fillGrid = function()
- {
- var _loc3_ = undefined;
- var _loc5_ = undefined;
- var _loc6_ = undefined;
- var _loc4_ = undefined;
- var _loc2_ = 0;
- while(_loc2_ < 64)
- {
- _loc3_ = this.pColours.slice();
- if(Math.round(_loc2_ % 8) > 1)
- {
- _loc6_ = this.getCellColour(_loc2_ - 1);
- if(_loc6_ - this.getCellColour(_loc2_ - 2) == 0)
- {
- _loc4_ = _loc3_.getItemIndex(_loc6_);
- _loc3_.splice(_loc4_,1);
- }
- }
- if(Math.floor(_loc2_ / 8) > 1)
- {
- _loc5_ = this.getCellColour(_loc2_ - 8);
- if(_loc5_ - this.getCellColour(_loc2_ - 16) == 0)
- {
- _loc4_ = _loc3_.getItemIndex(_loc5_);
- _loc3_.splice(_loc4_,1);
- }
- }
- this.pData[_loc2_] = _loc3_[Math.round(Math.random() * (_loc3_.length - 1))];
- _loc2_ = _loc2_ + 1;
- }
- };
- GameGrid.prototype.getCellColour = function(aNum)
- {
- var _loc2_ = this.pData[aNum];
- return _loc2_;
- };
- GameGrid.prototype.printGrid = function()
- {
- var _loc3_ = "";
- var _loc4_ = 0;
- while(_loc4_ < 8)
- {
- _loc3_ = "";
- var _loc2_ = 0;
- while(_loc2_ < 8)
- {
- _loc3_ += this.getCellColour(_loc4_ * 8 + _loc2_);
- _loc2_ = _loc2_ + 1;
- }
- _loc4_ = _loc4_ + 1;
- }
- };
- this.init = function()
- {
- this.pBlockCount = 0;
- this.pLevelEnd = false;
- this.pRange = 0;
- this.pLevel = 1;
- this.attachMovie("mc.selector","selector_mc",10000);
- this.pGrid = new GameGrid(8);
- this.pTileLocs = new Array(64);
- this.pTileCheck = 0;
- this.pSwappedTiles = new Array(2);
- this.pClearedTiles = new Array();
- this.setMask(this.tileMask_mc);
- this.pComboSnd = new Sound(this);
- this.pComboSnd.attachSound("snd.combo");
- this.pErrorSnd = new Sound(this);
- this.pErrorSnd.attachSound("snd.error");
- this.pSwishSnd = new Sound(this);
- this.pSwishSnd.attachSound("snd.swish");
- this.pBellsSnd = new Sound(this);
- this.pBellsSnd.attachSound("snd.bells");
- var _loc3_ = undefined;
- var _loc2_ = 0;
- while(_loc2_ < 64)
- {
- _loc3_ = new Object();
- _loc3_.pNum = _loc2_;
- _loc3_.pPos = new Object();
- _loc3_.pPos.x = -140 + 40 * (_loc2_ % 8);
- _loc3_.pPos.y = -140 + 40 * Math.floor(_loc2_ / 8);
- _loc3_.pColour = 1;
- this.attachMovie("mc.tile","t" + _loc2_ + "_mc",_loc2_,_loc3_);
- this.pTileLocs[_loc2_] = "t" + _loc2_ + "_mc";
- _loc2_ = _loc2_ + 1;
- }
- };
- this.printTileLocs = function()
- {
- var _loc6_ = 0;
- while(_loc6_ < 8)
- {
- var _loc4_ = "";
- var _loc3_ = 0;
- while(_loc3_ < 8)
- {
- var _loc5_ = _loc6_ * 8 + _loc3_;
- var _loc2_ = this.pTileLocs[_loc5_];
- _loc2_ = _loc2_.slice(1,-3);
- _loc4_ = _loc4_ + _loc2_ + ", ";
- _loc3_ = _loc3_ + 1;
- }
- _loc6_ = _loc6_ + 1;
- }
- };
- this.updateBlockCount = function()
- {
- this.pComboSnd.start();
- this.pBlockCount = this.pBlockCount + 1;
- if(this.pLevel < 5)
- {
- this.pLevelEnd = this.pBlockCount >= 20;
- }
- };
- this.gameOver = function()
- {
- this.pTileCheck = 0;
- var _loc2_ = 0;
- while(_loc2_ < 64)
- {
- this[this.pTileLocs[_loc2_]].destroyTile();
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- this.pBellsSnd.start();
- };
- this.tileDestroyDone = function()
- {
- if(--this.pTileCheck == 0)
- {
- this._parent.gameover_mc.gotoAndPlay("end");
- }
- };
- this.swapBlocks = function(aB1, aB2, aReturn)
- {
- this.selector_mc.setActive(false);
- var _loc5_ = -140 + 40 * (aB1 % 8);
- var _loc7_ = -140 + 40 * Math.floor(aB1 / 8);
- var _loc8_ = this.pTileLocs[aB1];
- var _loc4_ = -140 + 40 * (aB2 % 8);
- var _loc6_ = -140 + 40 * Math.floor(aB2 / 8);
- var _loc9_ = this.pTileLocs[aB2];
- if(_loc4_ != _loc5_)
- {
- var _loc10_ = (_loc4_ > _loc5_) * 2 - 1;
- }
- else
- {
- _loc10_ = (_loc6_ > _loc7_) * 2 - 1;
- }
- this[_loc8_].moveTile(_loc4_,_loc6_,_loc10_,aB2);
- this[_loc9_].moveTile(_loc5_,_loc7_,_loc10_,aB1);
- this.pSwappedTiles[0] = aB1;
- this.pSwappedTiles[1] = aB2;
- if(!aReturn)
- {
- this.pSwishSnd.start();
- this.pTileCheck = 2;
- }
- else
- {
- this.pErrorSnd.start();
- this.selector_mc.setActive(true);
- }
- this.pTileLocs[aB1] = _loc9_;
- this.pTileLocs[aB2] = _loc8_;
- this.pGrid.swapBlocks(aB1,aB2);
- };
- this.tileClearDone = function()
- {
- if(--this.pTileCheck == 0)
- {
- var _loc3_ = this.pGrid.removeBlocks();
- var _loc4_ = this.pTileLocs.slice();
- var _loc9_ = _loc3_[0].length;
- var _loc2_ = 0;
- while(_loc2_ < _loc9_)
- {
- var _loc5_ = _loc3_[0][_loc2_][0];
- var _loc6_ = _loc3_[0][_loc2_][1];
- this[_loc4_[_loc5_]].dropTile(_loc6_,_loc5_);
- this.pTileLocs[_loc5_ + _loc6_ * 8] = _loc4_[_loc5_];
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- _loc9_ = _loc3_[1].length;
- _loc2_ = 0;
- while(_loc2_ < _loc9_)
- {
- _loc5_ = _loc3_[1][_loc2_][0];
- var _loc7_ = _loc3_[1][_loc2_][1];
- var _loc8_ = _loc3_[1][_loc2_][2];
- this[_loc4_[_loc5_]].renewTile(_loc7_,_loc8_);
- this.pTileLocs[_loc7_] = _loc4_[_loc5_];
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- }
- };
- this.tileScaleDone = function()
- {
- if(--this.pTileCheck == 0)
- {
- this._parent.scores_mc.clearBonus();
- this._parent.scores_mc.updateLevel();
- this.pRange = Math.min(++this.pRange,8);
- this.loadGrid(this.pRange);
- this._parent.timer_mc.increaseSpeed();
- this.pLevelEnd = false;
- }
- };
- this.tileDropDone = function()
- {
- if(--this.pTileCheck == 0)
- {
- var _loc3_ = this.pGrid.checkGrid();
- var _loc4_ = _loc3_.length;
- this.pTileCheck = 0;
- this.pClearedTiles.splice(0);
- if(_loc4_ > 2)
- {
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- this[this.pTileLocs[_loc3_[_loc2_]]].removeTile();
- this.pClearedTiles.push(_loc3_[_loc2_]);
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- }
- if(_loc4_ == 0)
- {
- if(this.pLevelEnd)
- {
- _loc2_ = 0;
- while(_loc2_ < 64)
- {
- this[this.pTileLocs[_loc2_]].scaleTile();
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- this.pLevel = this.pLevel + 1;
- this._parent.soul_mc.clearMap();
- }
- else
- {
- this._parent.scores_mc.clearBonus();
- this.selector_mc.setActive(true);
- this._parent.timer_mc.resumeTimer();
- if(this.pBlockCount == 0)
- {
- this.pBellsSnd.start();
- }
- }
- }
- }
- };
- this.tileSwapDone = function()
- {
- if(--this.pTileCheck == 0)
- {
- this._parent.timer_mc.pauseTimer();
- var _loc4_ = this.pGrid.checkBlocks(this.pSwappedTiles[0]);
- var _loc3_ = this.pGrid.checkBlocks(this.pSwappedTiles[1]);
- var _loc5_ = _loc4_.length;
- var _loc6_ = _loc3_.length;
- if(!(_loc5_ > 2 || _loc6_ > 2))
- {
- this.swapBlocks(this.pSwappedTiles[1],this.pSwappedTiles[0],1);
- this._parent.timer_mc.resumeTimer();
- }
- else
- {
- this.pTileCheck = 0;
- this.pClearedTiles.splice(0);
- if(_loc5_ > 2)
- {
- var _loc2_ = 0;
- while(_loc2_ < _loc5_)
- {
- this[this.pTileLocs[_loc4_[_loc2_]]].removeTile();
- this.pClearedTiles.push(_loc4_[_loc2_]);
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- }
- if(_loc6_ > 2)
- {
- _loc2_ = 0;
- while(_loc2_ < _loc6_)
- {
- this[this.pTileLocs[_loc3_[_loc2_]]].removeTile();
- this.pClearedTiles.push(_loc3_[_loc2_]);
- this.pTileCheck = this.pTileCheck + 1;
- _loc2_ = _loc2_ + 1;
- }
- }
- }
- }
- };
- this.loadGrid = function(tRange)
- {
- this.pRange = tRange;
- this._parent.timer_mc.resetTimer();
- this.pGrid.setRange(tRange);
- this.pBlockCount = 0;
- var _loc3_ = undefined;
- var _loc2_ = 0;
- while(_loc2_ < 64)
- {
- _loc3_ = this["t" + _loc2_ + "_mc"];
- _loc3_.pNum = _loc2_;
- _loc3_.pPos.x = -140 + 40 * (_loc2_ % 8);
- _loc3_.pPos.y = -140 + 40 * Math.floor(_loc2_ / 8);
- _loc3_.pColour = this.pGrid.getCellColour(_loc2_);
- this.pTileLocs[_loc2_] = "t" + _loc2_ + "_mc";
- _loc3_.startTile();
- _loc2_ = _loc2_ + 1;
- }
- this.pTileCheck = 64;
- };
- this.init();
- stop();
-